<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>客户名称：</label>
                            <input type="text" name="userId"/>
                        </li>
                        <li>
                            <label>是否支付：</label>
                            <select name="isPay" th:with="type=${@dict.getType('sys_yes_no')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"   ></option>
                            </select>
                        </li>
                        <li>
                            <label>订单状态：</label>
                            <select name="status" th:with="type=${@dict.getType('sys_order_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>


                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>


        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">

    var editFlag = [[${@permission.hasPermi('car:order:edit')}]];
    var removeFlag = [[${@permission.hasPermi('car:order:remove')}]];
    var isPayDatas = [[${@dict.getType('sys_yes_no')}]];
    var statusDatas = [[${@dict.getType('sys_order_status')}]];
    var prefix = ctx + "eat/order";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            detailUrl: prefix + "/detail/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "订单",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '订单编号',

                },
                {
                    field: 'userName',
                    title: '客户名称'
                },

                {
                    field: 'status',
                    title: '订单状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'orderName',
                    title: '名称'
                },
                {
                    field: 'salesPrice',
                    title: '销售金额'
                },
                {
                    field: 'isPay',
                    title: '是否支付',
                    formatter: function (value, row, index) {


                        if (value == 'N') {
                            value = '未支付';
                        } else {
                            value = '已支付';
                        }

                        return '<span class="paySpan"   data-time = "' + row.createTime + '"  data-pay="' + value + '" >' + value + '</span>';
                    }
                },
                {
                    field: 'paymentTime',
                    title: '付款时间'
                },
                {
                    field: 'remark',
                    title: '备注'
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-search"></i>查看</a> ');

                        if (row.isPay == 'N' && row.status == 1) {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="pay(\'' + row.id + '\')"><i class="fa fa-cny"></i>支付</a> ');
                        }
                        if (row.isPay == 'N' && row.status == 1) {
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>取消</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    function pay(id) {
        $.modal.confirm("确认您已核对订单信息，并支付吗？", function () {
            $.modal.confirm("是否确认支付？", function () {
            $.operate.post(prefix + "/pay?id=" + id, {});
            })
        })
    }


    $(function () {

        setInterval(function () {

            var paySpan = $(".paySpan");
            paySpan.each(function () {


                var isPay = $(this).attr("data-pay")
                if (isPay == '未支付') {
                    var createTime = new Date($(this).attr("data-time")).getTime() / 1000;
                    var nowTime = new Date().getTime() / 1000;

                    if (nowTime - createTime < 30 * 60) {
                        //需在30分钟内支付
                        var time = 30 * 60 - (nowTime - createTime);

                        var min = Math.floor(time / 60);
                        var second = Math.round(time % 60);
                        if (min > 0) {
                            $(this).text("请在" + min + "分" + second + "秒内支付");
                        } else {
                            $(this).text("请在" + second + "秒内支付");
                        }
                        if (min <= 0 && second <= 0) {
                            $(this).text("未支付");
                            $(this).removeClass("paySpan")
                        }

                    }


                }


            })

        }, 1000)


    })


</script>
</body>
</html>
